package com.longsys.eventsourcing.demo.eventsourcing.repository;

import com.longsys.eventsourcing.demo.eventsourcing.domain.RoleAggr;
import com.longsys.eventsourcing.demo.mapper.RoleMapper;
import com.longsys.eventsourcing.demo.model.Role;
import com.longsys.framework.eventsourcing.sbclient.core.AggregateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author guozhu.huang
 * @date 2021/9/26 17:43
 */
@Repository
public class RoleAggrRepository implements AggregateRepository<RoleAggr> {

    @Autowired
    private RoleMapper roleMapper;

    public RoleAggr findById(Object id) {
        int roleId = (Integer) id;
        Role role = roleMapper.selectById(roleId);

        RoleAggr roleAggr = new RoleAggr();
        roleAggr.setRoleId(roleId);
        roleAggr.setRoleName(role.getRoleName());

        return roleAggr;
    }
}
